<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>ajax</title>
<style type="text/css"></style>
</head>
<body>
<p><input id="text" value="" type="text" onkeyup="getCustomerInfo()" /></p>
<p id="content"></p>
<script src="json.js" type="text/javascript"></script>
<script type="text/javascript">

var request=false;
try{
	request=new XMLHttpRequest();
}
catch(trymicrosoft){
	try{
		request=new ActiveXObject("Msxm12.XMLHTTP");
	}
	catch(othermicrosoft){
		try{
			request=new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch(failed){
			request=flase;
		}
	}
}
if (!request)
alert("Error initializing XMLHttpRequest !")
function getCustomerInfo(){		
	var url="/ajax_post.php";
	
	var people = 
  { "programmers": [ 
    { "firstName": "Brett", "lastName":"McLaughlin", "email": "brett@newInstance.com" }, 
    { "firstName": "Jason", "lastName":"Hunter", "email": "jason@servlets.com" }, 
    { "firstName": "Elliotte", "lastName":"Harold", "email": "elharo@macfaq.com" } 
   ], 
  "authors": [ 
    { "firstName": "Isaac", "lastName": "Asimov", "genre": "science fiction" }, 
    { "firstName": "Tad", "lastName": "Williams", "genre": "fantasy" }, 
    { "firstName": "Frank", "lastName": "Peretti", "genre": "christian fiction" } 
   ], 
  "musicians": [ 
    { "firstName": "Eric", "lastName": "Clapton", "instrument": "guitar" }, 
    { "firstName": "Sergei", "lastName": "Rachmaninoff", "instrument": "piano" } 
   ] 
  }
  	var mypeople=people.toJSONString()
  	var data="phone="+mypeople;;
	request.open("post",url,true);
	request.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	request.onreadystatechange=updatePage;
	request.send(data);	
}
function updatePage(){
	if(request.readyState==4)
		if(request.status==200)
		//var response=request.responseText.split("|");		
		document.getElementById("content").innerHTML=request.responseText;	
		
}

</script>
</body>
</html>
